import java.util.HashSet;
import java.util.Set;

public class Solution1015 {
    public int smallestRepunitDivByK(int k) {
        Set<Integer> set=new HashSet<>();
        int t=1%k,ans=1;
        while (true){
            if (t==0){
                return ans;
            }else{
                if (set.contains(t%k)){
                    return -1;
                }
                set.add(t%k);
                t=(t*10+1)%k;
                ans++;
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution1015().smallestRepunitDivByK(3));
    }
}
